class ReservationController {
    def scaffold = Reservation

    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max)params.max = 10
        [ reservationList: Reservation.list( params ) ]
    }

    def show = {
        [ reservation : Reservation.get( params.id ) ]
    }

    def delete = {
        def reservation = Reservation.get( params.id )
        if(reservation) {
            reservation.delete()
            flash.message = "Reservation ${params.id} deleted."
            redirect(action:list)
        }
        else {
            flash.message = "Reservation not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def reservation = Reservation.get( params.id )

        if(!reservation) {
                flash.message = "Reservation not found with id ${params.id}"
                redirect(action:list)
        }
        else {
            return [ reservation : reservation ]
        }
    }

    def update = {
        def reservation = Reservation.get( params.id )
        if(reservation) {
             reservation.properties = params
            if(reservation.save()) {
                flash.message = "Reservation ${params.id} updated."
                redirect(action:show,id:reservation.id)
            }
            else {
                render(view:'edit',model:[reservation:reservation])
            }
        }
        else {
            flash.message = "Reservation not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
      def reservation = new Reservation()
      reservation.properties = params
      return ['reservation':reservation]
    }

    def save = {
        def reservation = new Reservation()
        reservation.properties = params
        if(reservation.save()) {
            flash.message = "Reservation ${reservation.id} created."
            redirect(action:show,id:reservation.id)
        }
        else {
            render(view:'create',model:[reservation:reservation])
        }
    }

}